<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import SubmitBtn from '@/components/SubmitBtn.vue'
import { getCurrentTime } from '@/utils/index.js'
import store from '@/store/index.js'

const formData = ref({
	consultType: "", // 类型
	content: "", // 建议内容
	createdAt: null, // 当前时间
	userId: store.state.userid ?? ''
})

const list = [
	{
		value: '1',
		label: '物流咨询'
	},
	{
		value: '2',
		label: '价格咨询'
	}, {
		value: '3',
		label: '服务咨询'
	}, {
		value: '4',
		label: '投诉建议咨询'
	}, {
		value: '5',
		label: '其他'
	}
]
const selectconsultTypeShow = ref(false)
const typeStr = ref("")
const confirm = e => {
	const { value, label } = e[0]
	formData.value.consultType = label
	typeStr.value = label
}

onLoad(options => {
	if (!options.data) return
	const data = JSON.parse(options.data)
	formData.value = { ...data }
	typeStr.value = data.consultType
})

const confing = {
	api: '/logistics/requests',
	requiredFields: [
		{
			key: "consultType",
			name: "咨询类型",
			type: 'select'
		},
		{
			key: 'content',
			name: '咨询内容',
		},
	]
}
const beforeSubmit = () => {
	formData.value.createdAt = getCurrentTime()
}

</script>

<template>
	<view class="carinfo page_container">
		<view class="content">
			<u-form :model="formData" label-width="150" @click="selectconsultTypeShow = true">
				<u-form-item label="咨询类型:" required>
					<u-input @click="selectconsultTypeShow = true" disabled v-model="typeStr" />
				</u-form-item>
				<u-form-item label="咨询内容:" required>
					<u-input v-model="formData.content" border type="textarea" placeholder="请输入建议" />
				</u-form-item>
			</u-form>
		</view>
		<u-select v-model="selectconsultTypeShow" :list="list" @confirm="confirm"></u-select>
		<SubmitBtn @beforeSubmit="beforeSubmit" v-bind="confing" :formData="formData" />
	</view>
</template>

<style lang="scss" scoped>
.carinfo {
	min-height: 100vh;
	background: #f5f5f5;
	padding-top: 20rpx;

	.content {
		background: #fff !important;
		border-radius: 20rpx;
		padding: 0 40rpx;
		margin-bottom: 100rpx;
	}
}
</style>